package dfsketches.gr3d;

import java.awt.Component;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

public class MouseRotate implements MouseListener, MouseMotionListener {

	private Controller control;
	private volatile static int x;
	private volatile static int y;
	private int x_sh;
	private int y_sh;

	public MouseRotate(Controller controller, int x_shift, int y_shift) {
		control = controller;
		x_sh = x_shift;
		y_sh = y_shift;
	}

	@Override
	public void mouseClicked(MouseEvent event) {
		x = event.getX() - x_sh;
		y = event.getY() - y_sh;
		control.mouseClicked(new MouseEvent((Component) event.getSource(),
				event.getID(), event.getWhen(), event.getModifiersEx(), x, y,
				event.getClickCount(), false, event.getButton()));
	}

	@Override
	public void mouseEntered(MouseEvent event) {
	}

	@Override
	public void mouseExited(MouseEvent event) {
	}

	@Override
	public void mousePressed(MouseEvent event) {
		x = event.getX() - x_sh;
		y = event.getY() - y_sh;
		control.mousePressed(new MouseEvent((Component) event.getSource(),
				event.getID(), event.getWhen(), event.getModifiersEx(), x, y,
				event.getClickCount(), false, event.getButton()));
	}

	@Override
	public void mouseReleased(MouseEvent event) {
		x = event.getX() - x_sh;
		y = event.getY() - y_sh;
		control.mouseReleased(new MouseEvent((Component) event.getSource(),
				event.getID(), event.getWhen(), event.getModifiersEx(), x, y,
				event.getClickCount(), false, event.getButton()));
	}

	@Override
	public void mouseDragged(MouseEvent event) {
	}

	@Override
	public void mouseMoved(MouseEvent event) {
		x = event.getX() - x_sh;
		y = event.getY() - y_sh;
		control.mouseReleased(new MouseEvent((Component) event.getSource(),
				event.getID(), event.getWhen(), event.getModifiersEx(), x, y,
				event.getClickCount(), false, event.getButton()));
	}
}